package approve.action;

import model.pojo.Document;
import model.pojo.Employee;
import model.pojo.Yourapprovedoc;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.TextView;

public class Re_ViewForm14 extends Activity {
	// component
	TextView la_title, la_description, la_content;
	EditText title, description;
	WebView content;
	TextView la_createDate,la_writer,re_createDate;
	EditText re_employee;
	// bundle
	Document doc = null;
	String database = "admin";
	String lang = "EN";
	Bundle language = null;
	Employee emp = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.re_viewform14);
		getComponent();

		loadBundle();
		loadLanguage();

		viewDocument();

	}

	private void getComponent() {
		la_createDate=(TextView) findViewById(R.id.la_createDate);
		la_writer=(TextView) findViewById(R.id.la_writer);
		re_createDate = (TextView) findViewById(R.id.re_createDate);
		re_employee = (EditText) findViewById(R.id.re_employee);
		
		la_title = (TextView) findViewById(R.id.la_title);
		la_description = (TextView) findViewById(R.id.la_description);
		la_content = (TextView) findViewById(R.id.la_content);

		
		title = (EditText) findViewById(R.id.dailyreport_title);
		description = (EditText) findViewById(R.id.dailyreport_description);
		content = (WebView) findViewById(R.id.dailyreport_content);
	}

	private void loadBundle() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
			lang = extras.getString("lang");
			emp = (Employee) extras.get("em");
			doc = (Document) extras.get("doc");
			language = extras.getBundle(lang);
		}
	}

	private void loadLanguage() {
		if (language != null) {
			la_title.setText(language.getString("title"));
			la_description.setText(language.getString("Description"));
			la_content.setText(language.getString("content"));
			
			la_createDate.setText(language.getString("created-date")+": ");
			la_writer.setText(language.getString("writer")+"/"+language.getString("Department"));
		}
	}

	private void viewDocument() {
		if (doc != null) {
			re_createDate.setText(doc.getTimecreate()+"");
			re_employee.setText(doc.getEmployeeName()+"/"+doc.getDepartment());
			
			title.setText(doc.getTitle());

			description.setText(doc.getDescription());
			
			final String mimeType = "text/html";
			String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
//			header+="<script type=\"text/javascript\">   function showAndroidToast(toast) { var x=document.getElementById(\"myHeader\")" +
//					"      Android.setHTML(x);Android.getHTML();  } </script>";
//			MyJavaScriptInterface contentHtml =null; 
//			WebSettings settings = content.getSettings();
//
//		      settings.setPluginsEnabled(true);
//		      settings.setJavaScriptEnabled(true);
//		      settings.setJavaScriptCanOpenWindowsAutomatically(true);
		      
//			content.addJavascriptInterface(contentHtml=new MyJavaScriptInterface(this), "Android");
			content.loadData(header + "<div id=\"myHeader\">"+doc.getContent()+"</div>", mimeType, null);
			
			
			//sSystem.out.println("contentd: " + content.getContentDescription().toString());
		}
	}

	
}
